import { Component, OnInit, Input, ViewChild } from '@angular/core'; 
// import { ClueTableService } from '../../../../../@core/service/clue-service/clue-table.service'
import { HandleTableService } from '../../../../../@core/service/clue-service/handle-table.service';
import { CaseService } from '../../../../../@core/service/handle-service/api/case.service';

@Component({ 
  selector: 'app-table',
  templateUrl: './table.component.html', 
  styleUrls: ['./table.component.scss']
})
export class TableComponent implements OnInit {
  public total:number = 0;
  public page:number = 1;
  public selectedLimit:number = 10
  public limitOptions:any[] = [10,15,25]
  public pageList:any[] = [];
  public sessionUser:any;
  public partyPerson:any;
  public approvalAuth: boolean;                 // 审批权限


  @ViewChild('paginator') pageInator;
  @Input() clue;
  @Input() type;
  // clueTableService: ClueTableService;
  handleTableService: HandleTableService;
  constructor(
    // clueTableservice:ClueTableService,
    private caseService: CaseService,
    handleTableService: HandleTableService) {
    // this.clueTableService = clueTableservice;
    this.handleTableService = handleTableService;
  }
  ngOnInit() {
    this.goToPage({num:this.page,limit:this.selectedLimit}); 
    this.sessionUser=window.sessionStorage.getItem("userId");
    let approval = window.sessionStorage.getItem('approval');
    this.approvalAuth = approval == 'true' ? true : false;
  }
  goToPage($event){
    this.page = $event.num;
    //获取service值
    let {sourceType, caseType, currentStatus,currentLink, partyName, enrollmentStartDate,enrollmentEndDate,area,caseStatus}= this.handleTableService.searchOption;
   /*
     * 多条件查询线索信息包含分页信息
     * 返回多个线索信息
     * @param type 案件办理与案件审批控制位，handle | approval
     * @param pageIndex 页码
     * @param pageSize 条数
     * @param sourceType 案件来源
     * @param caseType 案件类型
     * @param currentStatus 案件状态
     * @param currentLink 案件环节
     * @param partyName 当事人
     * @param partyPerson 当前登录人
     * @param enrollmentStartDate 登记时间开始
     * @param enrollmentEndDate 登记时间结束
     * @param area 地区
     */
    // console.log(clueOriginValue);
    this.partyPerson = sessionStorage.getItem('userId');
    let personType:boolean = sessionStorage.getItem('approval') == 'true' ? true : false;
    this.caseService.casePageGet($event.num, $event.limit, sourceType,caseType,currentStatus,currentLink,partyName,this.partyPerson,enrollmentStartDate,enrollmentEndDate,area,caseStatus).subscribe((data) => {
      if (data['rel']) {
        this.pageList = data['data']['data'];
        this.page = data['data']['pageIndex'];
        this.total = data['data']['total'];        
      }else{
        this.pageList = [];
      }
    }, (error) => {
    })
  }
  onNext($event){
    console.log('调用下一页')
    this.goToPage($event)
  }
  onPrev($event){
    console.log('调用上一页')
    this.goToPage($event)
  }
  onFirst($event){
    console.log('调用首页')
    this.goToPage($event)
  }
  onLast($event){
    console.log('调用尾页')
    this.goToPage($event)
  }
  onSelect($event){
    this.selectedLimit = $event;
  }
}
